﻿

/* 
* 描述： 更新商品点击量
* productCode : 商品代码
*/
function updateProductClickCount(productCode)
{
    $.ajax
    (
        {
            url         :   "/Handler/ProductUpdateProcess.ashx",
            data        :   "Action=updateclick&ProductCode=" + productCode,
            type        :   "POST",
            success     : function(data){},
            error       : function(){} 
        }   
    );
}

var array_product = new Array(); 

    var j =0;
    for(var k = 0;k < 30;k++)
    {
        array_product[k] = new Array();
    }

 function showProduct(ProductCode,Color, isrefresh)
    {
        return updateProductHTML(ProductCode,Color, isrefresh);
    }
 function updateProductHTML(ProductCode,Color, isrefresh) 
    {
    var err=false;
    var doMouseOver=false;
    var color=document.getElementById("Hid_SelectColor").value;
         if(color != Color || isrefresh)
         {
            doMouseOver = true;
         }
         
         if(doMouseOver)
         {
                 j = 0;
                 for(; j < 30; j++ )
                 {
                        if(ProductCode == array_product[j][0])
                        {
                            break;
                        }
                 }
                 if(j == 30)
                {
                    document.getElementById("ProductName").innerHTML = err_mes;
                    err = false;
                }
                else
                {
                    document.getElementById("MiddleImage").src=array_product[j][20];
                    document.getElementById("ProductCode").innerHTML = array_product[j][0];
                    document.getElementById("ProductName").innerHTML=array_product[j][1];
                    if(SelectColor.length>0)
                    {
                        InitPsmallImg(SelectColor);
                        document.getElementById("Hid_SelectColor").value=SelectColor;                        
                    }
                    else
                    {
                        InitPsmallImg(array_product[j][17]);
                        document.getElementById("Hid_SelectColor").value=array_product[j][17];                        
                    }
                    document.getElementById("Brand").innerHTML = array_product[j][5];
                    document.getElementById("Fabrics").innerHTML = array_product[j][3];
                    document.getElementById("Weight").innerHTML = array_product[j][16];
                    document.getElementById("Style").innerHTML = array_product[j][21];  
                    document.getElementById("Stock").innerHTML = array_product[j][22];                   
                    document.getElementById("DPJ").innerHTML = array_product[j][4];  
                    var member=document.getElementById("MemberPrice"); 
                    var login=document.getElementById("login");
                    var zk=document.getElementById("Hid_ZK");
                    var GObuy=document.getElementById("GOBUY");
                    var GoCollect=document.getElementById("GoCollect");
                    if(zk.value.length>0)
                    {
                        var M_Price=0.0;
                        M_Price=(parseFloat(array_product[j][4])*parseFloat(zk.value));
                        member.innerHTML=M_Price.toFixed(2);
                        member.style.display="block";
                        login.style.display="none";
                        GObuy.href="javascript:addCart()";
                        GoCollect.href="javascript:AddCollect()";
                    }
                    else
                    {
                        member.innerHTML=array_product[j][4];
                        member.style.display="none";
                        login.style.display="block";
                        GObuy.href="../Users/login.aspx";
                        GoCollect.href="../Users/login.aspx";
                    }
                    
                    document.getElementById("ColorList").innerHTML = array_product[j][18];
                    if(SelectColor.length>0)
                    {                       
                        document.getElementById("Color"+SelectColor).className="rb_imglj";
                    }
                    else
                    {                        
                        document.getElementById("Color"+array_product[j][17]).className="rb_imglj";
                    }
                    updateSizeList();
                    document.getElementById("pnote").innerHTML = array_product[j][8];
                    err=true;
                }
            
                document.getElementById("ProductCode").value = ProductCode;
        }
        return err;
    }
function InitPsmallImg(color)
{
    var ul=document.getElementById("psmallimg");
    var index="Part"+color;
    ul.innerHTML="";
    for(var i=0;i<30;i++)
    {
        if(index==array_product[i][0])
        {            
            ul.innerHTML=ul.innerHTML+array_product[i][1];
        }
    }    
}
function InitPBigImg(color)
{
    var BigImag=document.getElementById("MiddleImage");
    var index="whole"+color;
    for(var i=0;i<30;i++)
    {
        if(index==array_product[i][0])
        {
            BigImag.src=array_product[i][1];
            var sc=array_product[i][1];
            var first=sc.lastIndexOf('_');
            var last=sc.lastIndexOf('.');
            var name=sc.substr(first+1,last-first-1);
            //点颜色时指定局部图那个被选中.
            var part=document.getElementsByTagName("li");
            for(var i=0;i<part.length;i++)
            {
                if(part[i].id!=null)
                {
                    if(part[i].id.length>4)
                    {
                        if(part[i].id.substr(0,4)=="Part")
                            {
                                 part[i].className="";
                            }
                    }
                }
            }
            if(document.getElementById("Part"+name)!=null)
            {
                document.getElementById("Part"+name).className="rb_imglj";
            }
        }
    }
}
function updateSizeList()
   {
        var options = array_product[j][19];
        var arr_option = options.split("&&");
        var sel = document.getElementById("sizeList");  
        var k = 0;
        while(k < sel.length )
        {
            sel.removeChild(sel.options(k));
            k=k+1;
        }        
        for(var i = 0; i < arr_option.length-1;i++)
        {
            eval("sel.options[i] = new Option" + arr_option[i] +";");
        }
   }  
 function setProduct(color) 
    {
        SelectColor=document.getElementById("Hid_SelectColor").value;
          if(color!=SelectColor)
          {
              document.getElementById("Amount").value="1";
              document.getElementById("Hid_SelectColor").value=color;
              var Color=document.getElementsByTagName("img");
            for(var i=0;i<Color.length;i++)
            {
                if(Color[i].id!=null)
                {
                    if(Color[i].id.length>5)
                    {
                        if(Color[i].id.substr(0,5)=="Color")
                        {
                             Color[i].className="";
                        }
                    }
                }
            }
           if(document.getElementById("Color"+color)!=null)
           {
              document.getElementById("Color"+color).className="rb_imglj"; //颜色选中的样式  
            }           
              InitPsmallImg(color);
              InitPBigImg(color);
          }

    }
function setBigImg(pname)
{
    var BigImag=document.getElementById("MiddleImage");    
    var aa=BigImag.src;       
    var first=aa.lastIndexOf('_');    
    var last=aa.lastIndexOf('.');     
    var name=aa.substr(first+1,last-first-1);   
    if(name!=pname)
    {
//        BigImag.src=aa.substr(0,first+1)+pname+aa.substr(last,aa.length-last);
        var middleImg = aa.substr(0,first+1)+pname+aa.substr(last,aa.length-last);
        //var bigImg = middleImg.replace("big", "show");
        if(window.event)
        {
            middleImg = window.event.srcElement.src.toLowerCase().replace("small", "big");
        }
        else
        {
            middleImg = event.target.src.toLowerCase().replace("small", "big");
        }
        
        showMirror(middleImg);
        var part=document.getElementsByTagName("li");
            for(var i=0;i<part.length;i++)
            {
                if(part[i].id!=null)
                {
                    if(part[i].id.length>4)
                    {
                        if(part[i].id.substr(0,4)=="Part")
                            {
                                 part[i].className="";
                            }
                    }
                }
            }
        if(document.getElementById("Part"+pname)!=null)
        {
            document.getElementById("Part"+pname).className="rb_imglj"; //切换局部图时设定样式.
        }
    }
}
/*function ShowBigImg()
{
//    //商品编码
//    var Pro = document.getElementById("ProductCode");
//    var productID = "";
//    if (Pro != null)
//        productID = Pro.innerHTML;
//    //颜色
//    var color=document.getElementById("Hid_SelectColor");
//    var colorvalue="";
//    if(color!=null)    
//    {
//        colorvalue=color.value;
//    }
//    //图片名
//    var oimg=document.getElementById("MiddleImage");
//    var img=oimg.src;
//   // window.open("ShowImg.aspx?ProductID="+productID+"&color="+colorvalue+"&img="+img);
//    window.open("ShowImg.aspx?img="+imgvar middleImg = document.getElementById("MiddleImage").src;
    if(middleImg)
    {
        var bigImg = middleImg.replace("big", "show");
        window.open(bigImg);
    }

}
function showMirror(middleImg)
{
    if(middleImg)
    {
        middleImg = middleImg.toLowerCase();
//        var bigImg = middleImg.replace("big", "show");
        document.getElementById("MiddleImage").src = middleImg;
//        $("#MiddleImage").attr("jqimg", bigImg);
        $("#MiddleImage").hide().fadeIn('slow');
    }
}*/